package com.lyf.scm.plan.api.controller;

import com.github.pagehelper.PageInfo;
import com.lyf.scm.common.model.ExcelExportDataDTO;
import com.lyf.scm.common.util.ExcelExportUtil;
import com.lyf.scm.plan.api.dto.*;
import com.lyf.scm.plan.api.dto.SalesPlanOtherDTO;
import com.lyf.scm.plan.domain.service.SalesPlanOtherEsService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;

/**
 * @Author: huangtao
 * @Description:
 * @Date: create in 2020/7/31
 */
@Slf4j
@Api(tags = "其他渠道计划")
@RequestMapping("/api/v1/salesPlanOther")
@RomeController
public class SalesPlanOtherController {
    @Resource
    private SalesPlanOtherEsService salesPlanOtherEsService;

    /*@PostMapping("/listWeek")
    @ApiOperation(value = "按条件查询其他渠道计划(周)")
    public Response<PageInfo<SalesPlanOtherInfoDTO>> listWeekBySelective(@RequestBody SalesPlanOtherDTO slaesPlanOther) {
        return Response.builderSuccess(salesPlanOtherEsService.listWeekBySelective(slaesPlanOther));
    }*/

    /*@PostMapping("/listAllByCycles")
    @ApiOperation(value = "查询全渠道其他渠道计划(范围)")
    public Response<List<SalesPlanOtherInfoDTO>> listAllByCycles(@RequestBody SalesPlanOtherDTO slaesPlanOther) {
        return Response.builderSuccess(salesPlanOtherEsService.listAllByCycles(slaesPlanOther));
    }*/

    @PostMapping("/importPlanType")
    @ApiOperation(value = "导入计划类型")
    public Response<Integer> importPlanType(@RequestBody List<SalesPlanOtherDTO> dtos, Integer impType, Long id) {
        return Response.builderSuccess(salesPlanOtherEsService.importPlanType(dtos, impType, id));
    }

    @PutMapping("/confirm")
    @ApiOperation("修改确认量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "unitType", value = "单位类型", required = true, paramType = "query", dataType = "long"),
            @ApiImplicitParam(name = "userId", value = "当前用户id", required = true, paramType = "query", dataType = "long"),
    })
    public Response<Boolean> confirm(@RequestBody List<SalesPlanOtherDTO> all, Long unitType, Integer level) {
        return Response.builderSuccess(salesPlanOtherEsService.confirm(all, unitType, level));
    }

    /*@PostMapping("/getOtherPlanLevel")
    @ApiOperation(value = "获取其他渠道计划当前用户级别")
    public Response<Integer> getOtherPlanLevel(Long userId) {
        return Response.builderSuccess(salesPlanOtherEsService.getOtherPlanLevel(userId));
    }*/

    @PostMapping("/addPlanOtherData")
    @ApiOperation("营销中心推送其他渠道计划数据")
    public Response<Boolean> addPlanOtherData(@Valid @RequestBody List<SalesPlanOtherSimpleDTO> dtoList) {
        return Response.builderSuccess(salesPlanOtherEsService.addPlanOtherData(dtoList));
    }

    @PostMapping("/updatePlanOtherType")
    @ApiOperation("营销中心修改其他渠道计划状态")
    public Response<Boolean> updatePlanOtherType(@RequestBody List<String> numbers) {
        return Response.builderSuccess(salesPlanOtherEsService.updatePlanOtherType(numbers));
    }

    @PostMapping("/export")
    @ApiOperation(value = "导出")
    public void export(@RequestBody SalesPlanOtherDTO salesPlanOtherDTO, @RequestParam Integer type, HttpServletResponse httpServletResponse) {
        try {
            ExcelExportDataDTO excelExportDataDTO = salesPlanOtherEsService.export(salesPlanOtherDTO, type);
            ExcelExportUtil.exportExcel(httpServletResponse, excelExportDataDTO);
        } catch (Exception e) {
            ExcelExportUtil.handleExceptionResponse(httpServletResponse, e);
        }
    }

    @PostMapping("/downLoadTemplate")
    @ApiOperation(value = "导出模板数据")
    public void downLoadTemplate(@RequestParam String type, @RequestParam String date, HttpServletResponse httpServletResponse) {
        try {
            ExcelExportDataDTO excelExportDataDTO = salesPlanOtherEsService.downLoadTemplate(type, date);
            ExcelExportUtil.exportExcelTemplate(httpServletResponse, excelExportDataDTO);
        } catch (Exception e) {
            ExcelExportUtil.handleExceptionResponse(httpServletResponse, e);
        }
    }


    @PostMapping("/updateConfirmStatus")
    @ApiOperation(value = "定时更新确认状态")
    public Response updateConfirmStatus() {
        salesPlanOtherEsService.updateConfirmStatus();
        return Response.builderSuccess(null);
    }

    /*@PostMapping("/pushDataToTransaction")
    @ApiOperation(value = "推送新品新店数据")
    public Response pushDataToTransaction(){
        return Response.builderSuccess(salesPlanOtherService.pushDataToTransaction());
    }*/

    @PostMapping("/delete")
    @ApiOperation(value = "删除对应标识数据")
    public Response delete(@RequestParam("opSign") String opSign) {
        salesPlanOtherEsService.delete(opSign);
        return Response.builderSuccess(null);
    }

    @PostMapping("/updatePlanCancelStatus")
    @ApiOperation(value = "修改营销中心取消状态")
    public Response updateCancelStatus() {
        salesPlanOtherEsService.updateCancelStatus();
        return Response.builderSuccess(null);
    }

    @PostMapping("/updateWarehouseCode")
    @ApiOperation(value = "更新数据中为空的仓库信息")
    public Response updateWarehouseCode() {
        salesPlanOtherEsService.updateWarehouseCode();
        return Response.builderSuccess(null);
    }
}
